﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.ApplicationBlocks.Data;
using System.Data;

namespace Site.Ajax
{
    /// <summary>
    /// Summary description for codefen
    /// </summary>
    public class codefen : IHttpHandler,System.Web.SessionState.IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            var Session = context.Session;
            string fen = (context.Request.Params["fen"]);
            context.Response.ContentType = "text/x-json";
            var Sqlstr = "select team from codefen where fen='" + fen + "' ";
            var dt = SqlHelper.ExecuteDataset(Session["Conn"].ToString(), CommandType.Text, Sqlstr).Tables[0];
            List<Team> teams = new List<Team>();
            foreach (DataRow dr in dt.Rows)
            {
                teams.Add(new Team() { Name = dr["team"].ToString() });
            }

            System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            string output =serializer.Serialize(teams);
            context.Response.Write(output);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

    [Serializable]    
    public class Team
    {
        public string Name { get; set; }
    }
}